package com.ruoyi.web.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PhonePlable;
import com.ruoyi.system.service.IPhonePlableService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 风险号码标签标管理Controller
 * 
 * @author ruoyi
 * @date 2022-09-23
 */
@Controller
@RequestMapping("/system/plable")
public class PhonePlableController extends BaseController
{
    private String prefix = "system/plable";

    @Autowired
    private IPhonePlableService phonePlableService;

    @RequiresPermissions("system:plable:view")
    @GetMapping()
    public String plable()
    {
        return prefix + "/plable";
    }

    /**
     * 查询风险号码标签标管理列表
     */
    @RequiresPermissions("system:plable:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PhonePlable phonePlable)
    {
        startPage();
        List<PhonePlable> list = phonePlableService.selectPhonePlableList(phonePlable);
        return getDataTable(list);
    }

    /**
     * 导出风险号码标签标管理列表
     */
    @RequiresPermissions("system:plable:export")
    @Log(title = "风险号码标签标管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PhonePlable phonePlable)
    {
        List<PhonePlable> list = phonePlableService.selectPhonePlableList(phonePlable);
        ExcelUtil<PhonePlable> util = new ExcelUtil<PhonePlable>(PhonePlable.class);
        return util.exportExcel(list, "风险号码标签标管理数据");
    }

    /**
     * 新增风险号码标签标管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存风险号码标签标管理
     */
    @RequiresPermissions("system:plable:add")
    @Log(title = "风险号码标签标管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PhonePlable phonePlable)
    {
        return toAjax(phonePlableService.insertPhonePlable(phonePlable));
    }

    /**
     * 修改风险号码标签标管理
     */
    @RequiresPermissions("system:plable:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        PhonePlable phonePlable = phonePlableService.selectPhonePlableById(id);
        mmap.put("phonePlable", phonePlable);
        return prefix + "/edit";
    }

    /**
     * 修改保存风险号码标签标管理
     */
    @RequiresPermissions("system:plable:edit")
    @Log(title = "风险号码标签标管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PhonePlable phonePlable)
    {
        return toAjax(phonePlableService.updatePhonePlable(phonePlable));
    }

    /**
     * 删除风险号码标签标管理
     */
    @RequiresPermissions("system:plable:remove")
    @Log(title = "风险号码标签标管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(phonePlableService.deletePhonePlableByIds(ids));
    }

    /**
     * 移动端添加方法
     * @param phonePlable
     * @return
     */
    @PostMapping( "/myadd")
    @ResponseBody
    public AjaxResult myadd(PhonePlable phonePlable){
        phonePlableService.insertPhonePlable(phonePlable);
        return success();
    }

    /**
     * 移动端查询
     * @param phoneNumber 手机号
     * @return
     */
    @PostMapping( "/mygetitem")
    @ResponseBody
    public AjaxResult mygetitem(@RequestParam("phoneNumber") String phoneNumber){
        PhonePlable phonePlable=new PhonePlable();
        phonePlable.setPhoneNumber(phoneNumber);
        phonePlableService.insertPhonePlable(phonePlable);
        return success();
    }
}
